//
//  ZGSSearchGoToViewController.m
//  Tour
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ZGSSearchGoToViewController.h"
#import "AdvanceEdit.h"
#import "ZGSearchCell.h"
#import "ScrollWebViewController.h"
@interface ZGSSearchGoToViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableDictionary *dic;
@property (nonatomic, retain)UIImageView *imageView;
@end

@implementation ZGSSearchGoToViewController
- (void)viewWillAppear:(BOOL)animated{
    self.navigationController.hidesBarsOnSwipe = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBarHidden = NO;
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - self.navigationController.navigationBar.frame.size.height) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[ZGSearchCell class] forCellReuseIdentifier:@"reuse"];
    self.dic = [NSMutableDictionary dictionary];
//    [self.tableView addSubview:self.view];
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 150;
    [_tableView release];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 2.5)];
//    self.tableView.tableHeaderView = self.imageView;
    
    
    [self creatData];
    
}

- (void)creatData{
    AFHTTPRequestOperationManager *manger = [AFHTTPRequestOperationManager manager];
    [manger GET:self.str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.dic = responseObject;
        [self.tableView reloadData];
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:self.dic[@"data"][@"photo"]]placeholderImage:[UIImage imageNamed:@"10.jpeg"]];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZGSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    if (indexPath.row == 0) {
        cell.labelUp.text = self.dic[@"data"][@"chinesename"];
        cell.labelDown.text = self.dic[@"data"][@"englishname"];
    }else if (indexPath.row == 1){
        cell.labelUp.text = @"简介";
        cell.labelDown.text = self.dic[@"data"][@"introduction"];
    }else if (indexPath.row == 2){
        cell.labelUp.text = @"地址";
        cell.labelDown.text = self.dic[@"data"][@"address"];
    }else{
        cell.labelUp.text = @"网址";
        cell.labelDown.text = self.dic[@"data"][@"qyerurl"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ScrollWebViewController *web =[[ScrollWebViewController alloc] init];
    if (indexPath.row == 3) {
       web.urlStr = self.dic[@"data"][@"qyerurl"];
        [self presentViewController:web animated:YES completion:^{
            
            
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
